/*
 * Copyright (c) Created by T C L on 2019.7.10.
 */

package cn.mumzone.pos.presenter;

import android.content.Context;

import java.util.List;

import cn.mumzone.basic.net.http.callback.ApiCallBack;
import cn.mumzone.basic.net.response.BaseResponse;
import cn.mumzone.basic.util.ToastUtil;
import cn.mumzone.pos.model.DepositGoodsRecordEntity;
import cn.mumzone.pos.model.ReceiveDepositGoodEntity;
import cn.mumzone.pos.model.source.MemberRepository;
import cn.mumzone.pos.presenter.contract.DepositReceiveContract;

public class DepositReceivePresenter implements DepositReceiveContract.Presenter {

    private Context context;
    private DepositReceiveContract.View view;

    private MemberRepository memberRepository;


    public DepositReceivePresenter(Context context, DepositReceiveContract.View view) {
        this.context = context;
        this.view = view;
        memberRepository = new MemberRepository();
    }

    @Override
    public void consignedGoodsReceiveRecord(String orderCode, String subCode, String goodsId) {
        memberRepository.consignedGoodsReceiveRecord(orderCode, subCode, goodsId,
                new ApiCallBack<List<DepositGoodsRecordEntity>>() {
                    @Override
                    public void onSuccess(List<DepositGoodsRecordEntity> consignedRecordEntities) {
                        view.setConsignedRecordData(consignedRecordEntities);
                    }

                    @Override
                    public void onError(BaseResponse response) {
                        ToastUtil.makeText(context, response.getMsg(), false);
                    }
                });

    }

    @Override
    public void receiveConsignedGoods(List<ReceiveDepositGoodEntity> receiveDepositGoodEntities) {
        memberRepository.receiveConsignedGoods(receiveDepositGoodEntities, new ApiCallBack<String>() {
            @Override
            public void onSuccess(String s) {
                view.resolveReceiveSuccess();
            }

            @Override
            public void onError(BaseResponse response) {
                ToastUtil.makeText(context, response.getMsg(), false);
                view.resolveReceiveFailed();
            }
        });
    }

}
